Question 1- Hogwarts House

Link to the Hogwarts house program.

ui.R

library(shiny)
shinyUI(pageWithSidebar(
  headerPanel("Hogwarts House Selection"),
  sidebarPanel(
    selectInput("house","Select your main trait", 
                choices = c("Brave", "Cunning", "Loyal", "Intelligent"))
  ),
   mainPanel(
     h3('Your House is:'),
     verbatimTextOutput("selected_house")
  )))

server.R

shinyServer(function(input, output){
  Hogwarts_house <- reactive({
    switch(input$house,
    "Brave" = "Gryffindor",
    "Cunning" = "Slytherin",
    "Loyal" = "Hufflepuff",
    "Intelligent" = "Ravenclaw")
    })
   output$selected_house<- renderPrint(Hogwarts_house())
})



Question 2- Plotly from Assignment 3

Assignment 3- Question 2

dat_class= read.table("https://raw.githubusercontent.com/bcaffo/ds4bme/master/data/classInterests.txt", header=TRUE)
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
class_plot <- ggplot(dat_class,aes(x=Year,fill= Program))
class_plot = class_plot + geom_bar()

ggplotly(class_plot)

Assignment 3- Question 3

library(ggmosaic)
dat_class= read.table("https://raw.githubusercontent.com/bcaffo/ds4bme/master/data/classInterests.txt", header=TRUE)
mosaic_class <- ggplot(data=dat_class) +
  geom_mosaic(aes(x=product(Year), fill = Program)) 

ggplotly(mosaic_class)

Assignment 3- Question 5

dat_health= read.csv("https://raw.githubusercontent.com/jhu-advdatasci/2018/master/data/KFF/healthcare-spending.csv", skip=2)
dat_health_states <- dat_health[-c(1,53:61),]
library(reshape)
## 
## Attaching package: 'reshape'
## The following object is masked from 'package:plotly':
## 
##     rename
health_states_melt <- melt(dat_health_states, id.vars = "Location")
health_plot <- ggplot(health_states_melt,aes(x=variable, y=value, group= Location, color=Location))
health_plot = health_plot + geom_line()
health_plot = health_plot + theme(axis.text.x = element_text(angle = 90))

ggplotly(health_plot)

Assignment 3- Question 6

avg<- rowMeans(dat_health_states[,-1])
health_states_avg <-  data.frame(Location=dat_health_states[,1], Spending= avg)
health_barplot <- ggplot(health_states_avg, aes(x=Location, y=Spending))
health_barplot <- health_barplot + geom_col()
health_barplot = health_barplot + theme(axis.text.x = element_text(angle = 90))

ggplotly(health_barplot)



Question 3 - BMI Calculator

Link to the BMI calculator program.

ui.R

shinyUI(
  pageWithSidebar(
    headerPanel("BMI Calculator"),
    sidebarPanel(
      numericInput('height', 'Height (in)', 65, min=0, step = 1),
      numericInput('weight', 'Weight (lbs)', 150, min=0, step = 1),
      submitButton('Submit')
    ),
    mainPanel(
      h3('BMI- Results'),
      h4('Height you entered'),
      verbatimTextOutput("input_height"),
      h4('Weight you entered'),
      verbatimTextOutput("input_weight"),
      h4('Calculated BMI'),
      verbatimTextOutput("BMI_output")
    )))

server.R

BMI_calculator <- function(height, weight) (weight/(height)^2)*703

shinyServer(
  function(input, output) {
    output$input_height <- renderPrint({input$height})
    output$input_weight <- renderPrint({input$weight})
    output$BMI_output <- renderPrint({BMI_calculator(input$height, input$weight)})
  }
)